<script>
import { defineComponent } from 'vue'
import { useUserStore } from '@/stores/user'

export default defineComponent({
  name: 'UserHeader',
  computed: {
    // 获取当前用户信息
    currentUserInfo() {
      const userStore = useUserStore()
      return userStore.userInfo?.user || {}
    },
    // 获取当前用户角色
    currentUserRole() {
      const userStore = useUserStore()
      // 假设用户只有一个角色，如果有多个角色可以显示主要角色
      return userStore.userInfo?.roles?.[0] || {}
    }
  }
})
</script>

<template>
  <div class="user-header">
    <div class="logo">
      <img src="@/assets/logo.svg" alt="Logo" v-if="false">
      <div class="logo-placeholder">LOGO</div>
    </div>
    <div class="user-info">
      <div class="user-name">{{ currentUserInfo.userName || '用户名' }}</div>
      <div class="user-role">{{ currentUserRole.roleName || '用户' }}</div>
    </div>
  </div>
</template>

<style scoped>
.user-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
  padding: 0 20px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

.logo-placeholder {
  font-size: 24px;
  font-weight: bold;
  color: #409eff;
}

.user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.user-name {
  font-weight: bold;
  font-size: 16px;
}

.user-role {
  font-size: 12px;
  color: #999;
}
</style>